
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>YUI Library Examples: Drag &amp; Drop: Photo Browser</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    	<link rel="stylesheet" type="text/css" href="../../assets/yui.css" >

<style>
    /*Supplemental CSS for the YUI distribution*/
    #custom-doc { width: 95%; min-width: 950px; }
    #pagetitle {background-image: url(../../assets/bg_hd.gif);}
/*    #pagetitle h1 {background-image: url(../../assets/title_h_bg.gif);}*/
</style>

<link rel="stylesheet" type="text/css" href="../../assets/dpSyntaxHighlighter.css">

<!--there is no custom header content for this example-->

<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" />
<script type="text/javascript" src="../../build/yui/yui-min.js"></script>

</head>
<body id="yahoo-com" class="yui3-skin-sam  yui-skin-sam">
<div id="custom-doc" class="yui-t2">
<div id="hd">
	<div id="ygunav">
		<p>
            <em>
                <a href="http://developer.yahoo.com/yui/3/">YUI 3.x Home</a> <i> - </i>	
            </em>
		</p>
		<form action="http://search.yahoo.com/search" id="sitesearchform">
            <input name="vs" type="hidden" value="developer.yahoo.com">
            <input name="vs" type="hidden" value="yuiblog.com">
		    <div id="sitesearch">
		    	<label for="searchinput">Site Search (YDN &amp; YUIBlog): </label>
			    <input type="text" id="searchinput" name="p">
			    <input type="submit" value="Search" id="searchsubmit" class="ygbt">
		    </div>
		</form>
    </div>
	<div id="ygma"><a href="../../"><img src="../../assets/logo.gif"  border="0" width="200" height="93"></a></div>
	<div id="pagetitle"><h1>YUI Library Examples: Drag &amp; Drop: Photo Browser</h1></div>
</div>
<div id="bd">


	<div id="yui-main">
		<div class="yui-b">
		  <div class="yui-ge">
			  <div class="yui-u first example" id="main">

	<h2>Drag &amp; Drop: Photo Browser</h2>

	<div id="example" class="promo">
	<div class="example-intro">
	<p>Photo Browser built with YUI3 and <a href="http://developer.yahoo.com/yql/">YQL</a>. This example was part of the YUI3 presentation by <a href="http://blog.davglass.com/">Dav Glass</a> at <a href="http://openhacklondon.pbworks.com/">Open Hack : London</a></p>
	</div>	

	<div class="module example-container  newWindow">
			<div id="example-canvas" class="bd">

		<p class="newWindowButton yui-skin-sam">
        <span id="newWindowLink">
            <span class="first-child">
                <a href="photo-browser_source.html" target="_blank">View example in new window.</a>
            </span>
        </span>	
    </p>
	
		
		</div>
	</div>			
	</div>
		
	<h3>YQL</h3>
<p>This example uses the YQL Query Gallery module: <a href="http://yuilibrary.com/gallery/show/yql">http://yuilibrary.com/gallery/show/yql</a></p>
<p>Here is the Flickr YQL query used in this example.</p>
<style>
/**
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 */
.sql  {font-family:monospace;}
.sql .imp {font-weight: bold; color: red;}
.sql .kw1 {color: #993333; font-weight: bold;}
.sql .co1 {color: #808080; font-style: italic;}
.sql .co2 {color: #808080; font-style: italic;}
.sql .coMULTI {color: #808080; font-style: italic;}
.sql .es0 {color: #000099; font-weight: bold;}
.sql .br0 {color: #66cc66;}
.sql .sy0 {color: #66cc66;}
.sql .st0 {color: #ff0000;}
.sql .nu0 {color: #cc66cc;}
.sql span.xtra { display:block; }

</style>
<div id="syntax-d258279266016612b48bdc74bd39289f" class="yui-syntax-highlight"><div class="numbers"><pre class="sql" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw1">SELECT</span> <span class="sy0">*</span> <span class="kw1">FROM</span> flickr<span class="sy0">.</span>photos<span class="sy0">.</span>search<span class="br0">&#40;</span><span class="nu0">100</span><span class="br0">&#41;</span> <span class="kw1">WHERE</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#40;</span>text<span class="sy0">=</span><span class="st0">&quot;yuiconf&quot;</span><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1"><span class="kw1">AND</span> <span class="br0">&#40;</span>safe_search <span class="sy0">=</span> <span class="nu0">1</span><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1"><span class="kw1">AND</span> <span class="br0">&#40;</span>media <span class="sy0">=</span> <span class="st0">&quot;photos&quot;</span><span class="br0">&#41;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="sql" style="font-family:monospace;"><span class="kw1">SELECT</span> <span class="sy0">*</span> <span class="kw1">FROM</span> flickr<span class="sy0">.</span>photos<span class="sy0">.</span>search<span class="br0">&#40;</span><span class="nu0">100</span><span class="br0">&#41;</span> <span class="kw1">WHERE</span>
    <span class="br0">&#40;</span>text<span class="sy0">=</span><span class="st0">&quot;yuiconf&quot;</span><span class="br0">&#41;</span>
<span class="kw1">AND</span> <span class="br0">&#40;</span>safe_search <span class="sy0">=</span> <span class="nu0">1</span><span class="br0">&#41;</span>
<span class="kw1">AND</span> <span class="br0">&#40;</span>media <span class="sy0">=</span> <span class="st0">&quot;photos&quot;</span><span class="br0">&#41;</span></pre></div><textarea id="syntax-d258279266016612b48bdc74bd39289f-plain">SELECT * FROM flickr.photos.search(100) WHERE
    (text="yuiconf")
AND (safe_search = 1)
AND (media = "photos")</textarea></div>

<h3>Slider and StyleSheet</h3>
<p>In this example, we will use the Slider control to dynamically manipulate a CSS Style Rule.</p>
<p>First, we need to create the slider and render it.</p>
<div id="syntax-64b3619e39171e988437ffbd054ba4ce" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="co1">//Create and render the slider</span></div></li><li class="li1"><div class="de1"><span class="kw2">var</span> sl <span class="sy0">=</span> <span class="kw2">new</span> Y.<span class="me1">Slider</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    length<span class="sy0">:</span> <span class="st0">'200px'</span><span class="sy0">,</span> value<span class="sy0">:</span> <span class="nu0">40</span><span class="sy0">,</span> max<span class="sy0">:</span> <span class="nu0">70</span><span class="sy0">,</span> min<span class="sy0">:</span> <span class="nu0">5</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">render</span><span class="br0">&#40;</span><span class="st0">'.horiz_slider'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;"><span class="co1">//Create and render the slider</span>
<span class="kw2">var</span> sl <span class="sy0">=</span> <span class="kw2">new</span> Y.<span class="me1">Slider</span><span class="br0">&#40;</span><span class="br0">&#123;</span>
    length<span class="sy0">:</span> <span class="st0">'200px'</span><span class="sy0">,</span> value<span class="sy0">:</span> <span class="nu0">40</span><span class="sy0">,</span> max<span class="sy0">:</span> <span class="nu0">70</span><span class="sy0">,</span> min<span class="sy0">:</span> <span class="nu0">5</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">render</span><span class="br0">&#40;</span><span class="st0">'.horiz_slider'</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div><textarea id="syntax-64b3619e39171e988437ffbd054ba4ce-plain">//Create and render the slider
var sl = new Y.Slider({
    length: '200px', value: 40, max: 70, min: 5
}).render('.horiz_slider');</textarea></div><p>Now, we listen for the Slider's <code>valueChange</code> event. This event is fired when the value of the Slider has changed.</p>
<p>Next we use the StyleSheet utility to dynamically change a style rule to resize the images.
The style rule that we want to change is <code>#yui-main .yui-g ul li</code>. When the Slider's value changes, we will take the value and divide it by 2, then use that as the percentage width of the li. 
This will give us the effect we want (resizing images) without touching all the images via the DOM.
</p>
<div id="syntax-d330d2046d7868b71feb7c72d915956f" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="co1">//Listen for the change</span></div></li><li class="li1"><div class="de1">sl.<span class="me1">after</span><span class="br0">&#40;</span><span class="st0">'valueChange'</span><span class="sy0">,</span><span class="kw2">function</span> <span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="co1">//Insert a dynamic stylesheet rule:</span></div></li><li class="li1"><div class="de1">    <span class="kw2">var</span> sheet <span class="sy0">=</span> <span class="kw2">new</span> Y.<span class="me1">StyleSheet</span><span class="br0">&#40;</span><span class="st0">'image_slider'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">    sheet.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'#yui-main .yui-g ul li'</span><span class="sy0">,</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        width<span class="sy0">:</span> <span class="br0">&#40;</span>e.<span class="me1">newVal</span> <span class="sy0">/</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">'%'</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;"><span class="co1">//Listen for the change</span>
sl.<span class="me1">after</span><span class="br0">&#40;</span><span class="st0">'valueChange'</span><span class="sy0">,</span><span class="kw2">function</span> <span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="co1">//Insert a dynamic stylesheet rule:</span>
    <span class="kw2">var</span> sheet <span class="sy0">=</span> <span class="kw2">new</span> Y.<span class="me1">StyleSheet</span><span class="br0">&#40;</span><span class="st0">'image_slider'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    sheet.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'#yui-main .yui-g ul li'</span><span class="sy0">,</span> <span class="br0">&#123;</span>
        width<span class="sy0">:</span> <span class="br0">&#40;</span>e.<span class="me1">newVal</span> <span class="sy0">/</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">'%'</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div><textarea id="syntax-d330d2046d7868b71feb7c72d915956f-plain">//Listen for the change
sl.after('valueChange',function (e) {
    //Insert a dynamic stylesheet rule:
    var sheet = new Y.StyleSheet('image_slider');
    sheet.set('#yui-main .yui-g ul li', {
        width: (e.newVal / 2) + '%'
    });
});</textarea></div>
<h3>Event Delegation</h3>
<p>This listener listens for all <code>mouseup</code> events on the <code>document</code> and it will only fire when the target element matches the <code>*</code> selector (which should be all elements).</p>
<p>This way we can remove all the <code>selected</code> CSS classes from all the images in the browser when a <code>mouseup</code> occurs, only if the shift key was not pressed. We can then check to determine if the mouseup came from one of the images. If it has, add the selected class back to it.</p>

<div id="syntax-9807c3bbdbb208d95cf9a0cc7e6ac360" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="co1">//Listen for all mouseups on the document (selecting/deselecting images)</span></div></li><li class="li1"><div class="de1">Y.<span class="me1">delegate</span><span class="br0">&#40;</span><span class="st0">'mouseup'</span> <span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>e.<span class="me1">shiftKey</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//No shift key - remove all selected images</span></div></li><li class="li2"><div class="de2">        wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'img.selected'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">    <span class="co1">//Check if the target is an image and select it.</span></div></li><li class="li1"><div class="de1">    <span class="kw1">if</span> <span class="br0">&#40;</span>e.<span class="me1">target</span>.<span class="me1">test</span><span class="br0">&#40;</span><span class="st0">'#yui-main .yui-g ul li img'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        e.<span class="me1">target</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">    <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">,</span> document<span class="sy0">,</span> <span class="st0">'*'</span><span class="br0">&#41;</span><span class="sy0">;</span>    </div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;"><span class="co1">//Listen for all mouseups on the document (selecting/deselecting images)</span>
Y.<span class="me1">delegate</span><span class="br0">&#40;</span><span class="st0">'mouseup'</span> <span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>e.<span class="me1">shiftKey</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="co1">//No shift key - remove all selected images</span>
        wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'img.selected'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
    <span class="co1">//Check if the target is an image and select it.</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span>e.<span class="me1">target</span>.<span class="me1">test</span><span class="br0">&#40;</span><span class="st0">'#yui-main .yui-g ul li img'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        e.<span class="me1">target</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span><span class="sy0">,</span> document<span class="sy0">,</span> <span class="st0">'*'</span><span class="br0">&#41;</span><span class="sy0">;</span>    </pre></div><textarea id="syntax-9807c3bbdbb208d95cf9a0cc7e6ac360-plain">//Listen for all mouseups on the document (selecting/deselecting images)
Y.delegate('mouseup' , function(e) {
    if (!e.shiftKey) {
        //No shift key - remove all selected images
        wrapper.all('img.selected').removeClass('selected');
    }
    //Check if the target is an image and select it.
    if (e.target.test('#yui-main .yui-g ul li img')) {
        e.target.addClass('selected');
    }
}, document, '*');    </textarea></div>
<p>This listener, listens for all <code>click</code> events on the album list <code>#photoList li</code>. 
First, it stops the click, so the href is not followed. Next, it removes all the <code>selected</code> classes from the list. Then, it adds the <code>selected</code> class to the item that was clicked on.</p>
<p>After that UI setup, it uses Selectors to change the view of the images in the browser. 
First, it checks if we are viewing "all" or a "sub album". If all is selected, it removes the <code>hidden</code> class from all the images.
If it was an album, it adds the <code>hidden</code> class to all the images, then selects all the images with the class of its <code>id</code>, then it removes the hidden class from them.
</p>
<p>Basically, it hides all the images, then determines the ones it needs to show and removes the <code>hidden</code> class from them.</p>
<div id="syntax-ba030700c192a33c11b7c15a86b37e52" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="co1">//Listen for all clicks on the '#photoList li' selector</span></div></li><li class="li1"><div class="de1">Y.<span class="me1">delegate</span><span class="br0">&#40;</span><span class="st0">'click'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="co1">//Prevent the click</span></div></li><li class="li1"><div class="de1">    e.<span class="me1">halt</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">    <span class="co1">//Remove all the selected items</span></div></li><li class="li1"><div class="de1">    e.<span class="me1">currentTarget</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode'</span><span class="br0">&#41;</span>.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li.selected'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="co1">//Add the selected class to the one that one clicked</span></div></li><li class="li1"><div class="de1">    e.<span class="me1">currentTarget</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="co1">//The &quot;All Photos&quot; link was clicked</span></div></li><li class="li2"><div class="de2">    <span class="kw1">if</span> <span class="br0">&#40;</span>e.<span class="me1">currentTarget</span>.<span class="me1">hasClass</span><span class="br0">&#40;</span><span class="st0">'all'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//Remove all the hidden classes</span></div></li><li class="li1"><div class="de1">        wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'hidden'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//Another &quot;album&quot; was clicked, get its id</span></div></li><li class="li2"><div class="de2">        <span class="kw2">var</span> c <span class="sy0">=</span> e.<span class="me1">target</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'id'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//Hide all items by adding the hidden class</span></div></li><li class="li1"><div class="de1">        wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li'</span><span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'hidden'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//Now, find all the items with the class name the same as the album id</span></div></li><li class="li1"><div class="de1">        <span class="co1">//and remove the hidden class</span></div></li><li class="li2"><div class="de2">        wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li.'</span> <span class="sy0">+</span> c<span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'hidden'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">,</span> document<span class="sy0">,</span> <span class="st0">'#photoList li'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;"><span class="co1">//Listen for all clicks on the '#photoList li' selector</span>
Y.<span class="me1">delegate</span><span class="br0">&#40;</span><span class="st0">'click'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="co1">//Prevent the click</span>
    e.<span class="me1">halt</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co1">//Remove all the selected items</span>
    e.<span class="me1">currentTarget</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode'</span><span class="br0">&#41;</span>.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li.selected'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co1">//Add the selected class to the one that one clicked</span>
    e.<span class="me1">currentTarget</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co1">//The &quot;All Photos&quot; link was clicked</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span>e.<span class="me1">currentTarget</span>.<span class="me1">hasClass</span><span class="br0">&#40;</span><span class="st0">'all'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="co1">//Remove all the hidden classes</span>
        wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'hidden'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
        <span class="co1">//Another &quot;album&quot; was clicked, get its id</span>
        <span class="kw2">var</span> c <span class="sy0">=</span> e.<span class="me1">target</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'id'</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="co1">//Hide all items by adding the hidden class</span>
        wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li'</span><span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'hidden'</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="co1">//Now, find all the items with the class name the same as the album id</span>
        <span class="co1">//and remove the hidden class</span>
        wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li.'</span> <span class="sy0">+</span> c<span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'hidden'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span><span class="sy0">,</span> document<span class="sy0">,</span> <span class="st0">'#photoList li'</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div><textarea id="syntax-ba030700c192a33c11b7c15a86b37e52-plain">//Listen for all clicks on the '#photoList li' selector
Y.delegate('click', function(e) {
    //Prevent the click
    e.halt();
    //Remove all the selected items
    e.currentTarget.get('parentNode').all('li.selected').removeClass('selected');
    //Add the selected class to the one that one clicked
    e.currentTarget.addClass('selected');
    //The "All Photos" link was clicked
    if (e.currentTarget.hasClass('all')) {
        //Remove all the hidden classes
        wrapper.all('li').removeClass('hidden');
    } else {
        //Another "album" was clicked, get its id
        var c = e.target.get('id');
        //Hide all items by adding the hidden class
        wrapper.all('li').addClass('hidden');
        //Now, find all the items with the class name the same as the album id
        //and remove the hidden class
        wrapper.all('li.' + c).removeClass('hidden');
    }
}, document, '#photoList li');</textarea></div>

<h3>Full Source</h3>
<p>Here is the full commented JavaScript source for this example.</p>
<div id="syntax-1c523152372eedf102f48b5660168c42" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1">YUI<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="kw2">use</span><span class="br0">&#40;</span><span class="st0">'gallery-yql'</span><span class="sy0">,</span> <span class="st0">'node'</span><span class="sy0">,</span> <span class="st0">'anim'</span><span class="sy0">,</span> <span class="st0">'dd'</span><span class="sy0">,</span> <span class="st0">'slider'</span><span class="sy0">,</span> <span class="st0">'stylesheet'</span><span class="sy0">,</span> <span class="st0">'event-delegate'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>Y<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="co1">//Get a reference to the wrapper to use later and add a loading class to it.</span></div></li><li class="li1"><div class="de1">    <span class="kw2">var</span> wrapper <span class="sy0">=</span> Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#yui-main .yui-g ul'</span><span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'loading'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="co1">//Set its height to the height of the viewport so we can scroll it.</span></div></li><li class="li2"><div class="de2">    wrapper.<span class="me1">setStyle</span><span class="br0">&#40;</span><span class="st0">'height'</span><span class="sy0">,</span> <span class="br0">&#40;</span>wrapper.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'winHeight'</span><span class="br0">&#41;</span> <span class="sy0">-</span> <span class="nu0">50</span> <span class="br0">&#41;</span><span class="sy0">+</span> <span class="st0">'px'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'windowresize'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> wrapper.<span class="me1">setStyle</span><span class="br0">&#40;</span><span class="st0">'height'</span><span class="sy0">,</span> <span class="br0">&#40;</span>wrapper.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'winHeight'</span><span class="br0">&#41;</span> <span class="sy0">-</span> <span class="nu0">50</span> <span class="br0">&#41;</span><span class="sy0">+</span> <span class="st0">'px'</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="co1">//Make the YQL query.</span></div></li><li class="li1"><div class="de1">    <span class="kw2">new</span> Y.<span class="me1">yql</span><span class="br0">&#40;</span><span class="st0">'select * from flickr.photos.search(100) where text=&quot;openhacklondon&quot; and safe_search = 1 and media = &quot;photos&quot; and extras = &quot;o_dims&quot; and ((o_width = &quot;1600&quot; and o_height = &quot;1200&quot;) or (o_width = &quot;1200&quot; and o_height = &quot;1600&quot;) or (o_width = &quot;800&quot; and o_height = &quot;600&quot;) or (o_width = &quot;600&quot; and o_height = &quot;800&quot;))'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">if</span> <span class="br0">&#40;</span>e.<span class="me1">query</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">            <span class="kw2">var</span> photos <span class="sy0">=</span> e.<span class="me1">query</span>.<span class="me1">results</span>.<span class="me1">photo</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="co1">//Walk the returned photos array</span></div></li><li class="li1"><div class="de1">            Y.<span class="me1">each</span><span class="br0">&#40;</span>photos<span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>v<span class="sy0">,</span> k<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                <span class="co1">//Create our URL</span></div></li><li class="li1"><div class="de1">                <span class="kw2">var</span> url <span class="sy0">=</span> <span class="st0">'http:/'</span><span class="sy0">+</span><span class="st0">'/static.flickr.com/'</span> <span class="sy0">+</span> v.<span class="me1">server</span> <span class="sy0">+</span> <span class="st0">'/'</span> <span class="sy0">+</span> v.<span class="me1">id</span> <span class="sy0">+</span> <span class="st0">'_'</span> <span class="sy0">+</span> v.<span class="me1">secret</span> <span class="sy0">+</span> <span class="st0">'_m.jpg'</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2">                    <span class="co1">//Create the image and the LI</span></div></li><li class="li1"><div class="de1">                    li <span class="sy0">=</span> Y.<span class="me1">Node</span>.<span class="me1">create</span><span class="br0">&#40;</span><span class="st0">'&lt;li class=&quot;loading&quot;&gt;&lt;img src=&quot;'</span> <span class="sy0">+</span> url <span class="sy0">+</span> <span class="st0">'&quot; title=&quot;'</span> <span class="sy0">+</span> v.<span class="me1">title</span> <span class="sy0">+</span> <span class="st0">'&quot;&gt;&lt;/li&gt;'</span><span class="br0">&#41;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">                    <span class="co1">//Get the image from the LI</span></div></li><li class="li1"><div class="de1">                    img <span class="sy0">=</span> li.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'firstChild'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">                <span class="co1">//Append the li to the wrapper</span></div></li><li class="li2"><div class="de2">                wrapper.<span class="me1">appendChild</span><span class="br0">&#40;</span>li<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">                <span class="co1">//This little hack moves the tall images to the bottom of the list</span></div></li><li class="li1"><div class="de1">                <span class="co1">//So they float better ;)</span></div></li><li class="li1"><div class="de1">                img.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'load'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                    <span class="co1">//Is the height longer than the width?</span></div></li><li class="li2"><div class="de2">                    <span class="kw2">var</span> c <span class="sy0">=</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'height'</span><span class="br0">&#41;</span> <span class="sy0">&gt;</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'width'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">?</span> <span class="st0">'tall'</span> <span class="sy0">:</span> <span class="st0">'wide'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">                    <span class="kw1">this</span>.<span class="me1">addClass</span><span class="br0">&#40;</span>c<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">                    <span class="kw1">if</span> <span class="br0">&#40;</span>c <span class="sy0">===</span> <span class="st0">'tall'</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                        <span class="co1">//Move it to the end of the list.</span></div></li><li class="li1"><div class="de1">                        <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode.parentNode'</span><span class="br0">&#41;</span>.<span class="me1">removeChild</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">                        wrapper.<span class="me1">appendChild</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">                    <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">                    <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'loading'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">                <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">            <span class="co1">//Get all the newly added li's</span></div></li><li class="li1"><div class="de1">            wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li'</span><span class="br0">&#41;</span>.<span class="me1">each</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>node<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                <span class="co1">//Plugin the Drag plugin</span></div></li><li class="li1"><div class="de1">                <span class="kw1">this</span>.<span class="me1">plug</span><span class="br0">&#40;</span>Y.<span class="me1">Plugin</span>.<span class="me1">Drag</span><span class="sy0">,</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                    offsetNode<span class="sy0">:</span> <span class="kw2">false</span></div></li><li class="li2"><div class="de2">                <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">                <span class="co1">//Plug the Proxy into the DD object</span></div></li><li class="li1"><div class="de1">                <span class="kw1">this</span>.<span class="me1">dd</span>.<span class="me1">plug</span><span class="br0">&#40;</span>Y.<span class="me1">Plugin</span>.<span class="me1">DDProxy</span><span class="sy0">,</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                    resizeFrame<span class="sy0">:</span> <span class="kw2">false</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">                    moveOnEnd<span class="sy0">:</span> <span class="kw2">false</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2">                    borderStyle<span class="sy0">:</span> <span class="st0">'none'</span></div></li><li class="li1"><div class="de1">                <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="co1">//Create and render the slider</span></div></li><li class="li1"><div class="de1">            <span class="kw2">var</span> sl <span class="sy0">=</span> <span class="kw2">new</span> Y.<span class="me1">Slider</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">                length<span class="sy0">:</span> <span class="st0">'200px'</span><span class="sy0">,</span> value<span class="sy0">:</span> <span class="nu0">40</span><span class="sy0">,</span> max<span class="sy0">:</span> <span class="nu0">70</span><span class="sy0">,</span> min<span class="sy0">:</span> <span class="nu0">5</span></div></li><li class="li1"><div class="de1">            <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">render</span><span class="br0">&#40;</span><span class="st0">'.horiz_slider'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="co1">//Listen for the change</span></div></li><li class="li1"><div class="de1">            sl.<span class="me1">after</span><span class="br0">&#40;</span><span class="st0">'valueChange'</span><span class="sy0">,</span><span class="kw2">function</span> <span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                <span class="co1">//Insert a dynamic stylesheet rule</span></div></li><li class="li2"><div class="de2">                <span class="kw2">var</span> sheet <span class="sy0">=</span> <span class="kw2">new</span> Y.<span class="me1">StyleSheet</span><span class="br0">&#40;</span><span class="st0">'image_slider'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">                sheet.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'#yui-main .yui-g ul li'</span><span class="sy0">,</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                    width<span class="sy0">:</span> <span class="br0">&#40;</span>e.<span class="me1">newVal</span> <span class="sy0">/</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">'%'</span></div></li><li class="li1"><div class="de1">                <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">            <span class="co1">//Remove the DDM as a bubble target..</span></div></li><li class="li1"><div class="de1">            sl._dd.<span class="me1">removeTarget</span><span class="br0">&#40;</span>Y.<span class="me1">DD</span>.<span class="me1">DDM</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="co1">//Remove the wrappers loading class</span></div></li><li class="li1"><div class="de1">            wrapper.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'loading'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#ft'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'loading'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">        <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="co1">//Listen for all mouseups on the document (selecting/deselecting images)</span></div></li><li class="li1"><div class="de1">    Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'delegate'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>e.<span class="me1">shiftKey</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">            <span class="co1">//No shift key - remove all selected images</span></div></li><li class="li1"><div class="de1">            wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'img.selected'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//Check if the target is an image and select it.</span></div></li><li class="li1"><div class="de1">        <span class="kw1">if</span> <span class="br0">&#40;</span>e.<span class="me1">target</span>.<span class="me1">test</span><span class="br0">&#40;</span><span class="st0">'#yui-main .yui-g ul li img'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">            e.<span class="me1">target</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="sy0">,</span> document<span class="sy0">,</span> <span class="st0">'mouseup'</span><span class="sy0">,</span> <span class="st0">'*'</span><span class="br0">&#41;</span><span class="sy0">;</span>    </div></li><li class="li1"><div class="de1">    <span class="co1">//Listen for all clicks on the '#photoList li' selector</span></div></li><li class="li1"><div class="de1">    Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'delegate'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">        <span class="co1">//Prevent the click</span></div></li><li class="li1"><div class="de1">        e.<span class="me1">halt</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//Remove all the selected items</span></div></li><li class="li1"><div class="de1">        e.<span class="me1">currentTarget</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode'</span><span class="br0">&#41;</span>.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li.selected'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//Add the selected class to the one that one clicked</span></div></li><li class="li2"><div class="de2">        e.<span class="me1">currentTarget</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//The &quot;All Photos&quot; link was clicked</span></div></li><li class="li1"><div class="de1">        <span class="kw1">if</span> <span class="br0">&#40;</span>e.<span class="me1">currentTarget</span>.<span class="me1">hasClass</span><span class="br0">&#40;</span><span class="st0">'all'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">            <span class="co1">//Remove all the hidden classes</span></div></li><li class="li1"><div class="de1">            wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'hidden'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">        <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">            <span class="co1">//Another &quot;album&quot; was clicked, get its id</span></div></li><li class="li1"><div class="de1">            <span class="kw2">var</span> c <span class="sy0">=</span> e.<span class="me1">currentTarget</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'id'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="co1">//Hide all items by adding the hidden class</span></div></li><li class="li1"><div class="de1">            wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li'</span><span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'hidden'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">            <span class="co1">//Now, find all the items with the class name the same as the album id</span></div></li><li class="li1"><div class="de1">            <span class="co1">//and remove the hidden class</span></div></li><li class="li1"><div class="de1">            wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li.'</span> <span class="sy0">+</span> c<span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'hidden'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="sy0">,</span> document<span class="sy0">,</span> <span class="st0">'click'</span><span class="sy0">,</span> <span class="st0">'#photoList li'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">    <span class="co1">//Stop the drag with the escape key</span></div></li><li class="li1"><div class="de1">    Y.<span class="me1">one</span><span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'keypress'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//The escape key was pressed</span></div></li><li class="li1"><div class="de1">        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>e.<span class="me1">keyCode</span> <span class="sy0">===</span> <span class="nu0">27</span><span class="br0">&#41;</span> <span class="sy0">||</span> <span class="br0">&#40;</span>e.<span class="me1">charCode</span> <span class="sy0">===</span> <span class="nu0">27</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">            <span class="co1">//We have an active Drag</span></div></li><li class="li2"><div class="de2">            <span class="kw1">if</span> <span class="br0">&#40;</span>Y.<span class="me1">DD</span>.<span class="me1">DDM</span>.<span class="me1">activeDrag</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                <span class="co1">//Stop the drag</span></div></li><li class="li1"><div class="de1">                Y.<span class="me1">DD</span>.<span class="me1">DDM</span>.<span class="me1">activeDrag</span>.<span class="me1">stopDrag</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">        <span class="br0">&#125;</span></div></li><li class="li2"><div class="de2">    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="co1">//On the drag:mouseDown add the selected class</span></div></li><li class="li1"><div class="de1">    Y.<span class="me1">DD</span>.<span class="me1">DDM</span>.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'drag:mouseDown'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        e.<span class="me1">target</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'node'</span><span class="br0">&#41;</span>.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'img'</span><span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">    <span class="co1">//On drag start, get all the selected elements</span></div></li><li class="li1"><div class="de1">    <span class="co1">//Add the count to the proxy element and offset it to the cursor.</span></div></li><li class="li1"><div class="de1">    Y.<span class="me1">DD</span>.<span class="me1">DDM</span>.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'drag:start'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//How many items are selected</span></div></li><li class="li1"><div class="de1">        <span class="kw2">var</span> count <span class="sy0">=</span> wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'img.selected'</span><span class="br0">&#41;</span>.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">        <span class="co1">//Set the style on the proxy node</span></div></li><li class="li1"><div class="de1">        e.<span class="me1">target</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'dragNode'</span><span class="br0">&#41;</span>.<span class="me1">setStyles</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">            height<span class="sy0">:</span> <span class="st0">'25px'</span><span class="sy0">,</span> width<span class="sy0">:</span> <span class="st0">'25px'</span></div></li><li class="li1"><div class="de1">        <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'innerHTML'</span><span class="sy0">,</span> <span class="st0">'&lt;span&gt;'</span> <span class="sy0">+</span> count <span class="sy0">+</span> <span class="st0">'&lt;/span&gt;'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//Offset the dragNode</span></div></li><li class="li2"><div class="de2">        e.<span class="me1">target</span>.<span class="me1">deltaXY</span> <span class="sy0">=</span> <span class="br0">&#91;</span><span class="nu0">25</span><span class="sy0">,</span> <span class="nu0">5</span><span class="br0">&#93;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="co1">//We dropped on a drop target</span></div></li><li class="li1"><div class="de1">    Y.<span class="me1">DD</span>.<span class="me1">DDM</span>.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'drag:drophit'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//get the images that are selected.</span></div></li><li class="li2"><div class="de2">        <span class="kw2">var</span> imgs <span class="sy0">=</span> wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'img.selected'</span><span class="br0">&#41;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">            <span class="co1">//The xy position of the item we dropped on</span></div></li><li class="li1"><div class="de1">            toXY <span class="sy0">=</span> e.<span class="me1">drop</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'node'</span><span class="br0">&#41;</span>.<span class="me1">getXY</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">        imgs.<span class="me1">each</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>node<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">            <span class="co1">//Clone the image, position it on top of the original and animate it to the drop target</span></div></li><li class="li1"><div class="de1">            node.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode'</span><span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span>e.<span class="me1">drop</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'node'</span><span class="br0">&#41;</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'id'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="kw2">var</span> n <span class="sy0">=</span> node.<span class="me1">cloneNode</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'id'</span><span class="sy0">,</span> <span class="st0">''</span><span class="br0">&#41;</span>.<span class="me1">setStyle</span><span class="br0">&#40;</span><span class="st0">'position'</span><span class="sy0">,</span> <span class="st0">'absolute'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'body'</span><span class="br0">&#41;</span>.<span class="me1">appendChild</span><span class="br0">&#40;</span>n<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            n.<span class="me1">setXY</span><span class="br0">&#40;</span>node.<span class="me1">getXY</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">            <span class="kw2">new</span> Y.<span class="me1">Anim</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                node<span class="sy0">:</span> n<span class="sy0">,</span></div></li><li class="li1"><div class="de1">                to<span class="sy0">:</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                    height<span class="sy0">:</span> <span class="nu0">20</span><span class="sy0">,</span> width<span class="sy0">:</span> <span class="nu0">20</span><span class="sy0">,</span> opacity<span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">                    top<span class="sy0">:</span> toXY<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="sy0">,</span> left<span class="sy0">:</span> toXY<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span></div></li><li class="li2"><div class="de2">                <span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">                from<span class="sy0">:</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                    width<span class="sy0">:</span> node.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'offsetWidth'</span><span class="br0">&#41;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">                    height<span class="sy0">:</span> node.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'offsetHeight'</span><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1">                <span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2">                duration<span class="sy0">:</span> .5</div></li><li class="li1"><div class="de1">            <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">run</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="co1">//Update the count</span></div></li><li class="li1"><div class="de1">        <span class="kw2">var</span> count <span class="sy0">=</span> wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li.'</span> <span class="sy0">+</span> e.<span class="me1">drop</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'node'</span><span class="br0">&#41;</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'id'</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">        e.<span class="me1">drop</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'node'</span><span class="br0">&#41;</span>.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'span'</span><span class="br0">&#41;</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'innerHTML'</span><span class="sy0">,</span> <span class="st0">'('</span> <span class="sy0">+</span> count <span class="sy0">+</span> <span class="st0">')'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="co1">//Add drop support to the albums</span></div></li><li class="li1"><div class="de1">    Y.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'#photoList li'</span><span class="br0">&#41;</span>.<span class="me1">each</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>node<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>node.<span class="me1">hasClass</span><span class="br0">&#40;</span><span class="st0">'all'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">            <span class="co1">//make all albums Drop Targets except the all photos.</span></div></li><li class="li1"><div class="de1">            node.<span class="me1">plug</span><span class="br0">&#40;</span>Y.<span class="me1">Plugin</span>.<span class="me1">Drop</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">        <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;">YUI<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="kw2">use</span><span class="br0">&#40;</span><span class="st0">'gallery-yql'</span><span class="sy0">,</span> <span class="st0">'node'</span><span class="sy0">,</span> <span class="st0">'anim'</span><span class="sy0">,</span> <span class="st0">'dd'</span><span class="sy0">,</span> <span class="st0">'slider'</span><span class="sy0">,</span> <span class="st0">'stylesheet'</span><span class="sy0">,</span> <span class="st0">'event-delegate'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>Y<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="co1">//Get a reference to the wrapper to use later and add a loading class to it.</span>
    <span class="kw2">var</span> wrapper <span class="sy0">=</span> Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#yui-main .yui-g ul'</span><span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'loading'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co1">//Set its height to the height of the viewport so we can scroll it.</span>
    wrapper.<span class="me1">setStyle</span><span class="br0">&#40;</span><span class="st0">'height'</span><span class="sy0">,</span> <span class="br0">&#40;</span>wrapper.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'winHeight'</span><span class="br0">&#41;</span> <span class="sy0">-</span> <span class="nu0">50</span> <span class="br0">&#41;</span><span class="sy0">+</span> <span class="st0">'px'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'windowresize'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> wrapper.<span class="me1">setStyle</span><span class="br0">&#40;</span><span class="st0">'height'</span><span class="sy0">,</span> <span class="br0">&#40;</span>wrapper.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'winHeight'</span><span class="br0">&#41;</span> <span class="sy0">-</span> <span class="nu0">50</span> <span class="br0">&#41;</span><span class="sy0">+</span> <span class="st0">'px'</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co1">//Make the YQL query.</span>
    <span class="kw2">new</span> Y.<span class="me1">yql</span><span class="br0">&#40;</span><span class="st0">'select * from flickr.photos.search(100) where text=&quot;openhacklondon&quot; and safe_search = 1 and media = &quot;photos&quot; and extras = &quot;o_dims&quot; and ((o_width = &quot;1600&quot; and o_height = &quot;1200&quot;) or (o_width = &quot;1200&quot; and o_height = &quot;1600&quot;) or (o_width = &quot;800&quot; and o_height = &quot;600&quot;) or (o_width = &quot;600&quot; and o_height = &quot;800&quot;))'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span>e.<span class="me1">query</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="kw2">var</span> photos <span class="sy0">=</span> e.<span class="me1">query</span>.<span class="me1">results</span>.<span class="me1">photo</span><span class="sy0">;</span>
            <span class="co1">//Walk the returned photos array</span>
            Y.<span class="me1">each</span><span class="br0">&#40;</span>photos<span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>v<span class="sy0">,</span> k<span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="co1">//Create our URL</span>
                <span class="kw2">var</span> url <span class="sy0">=</span> <span class="st0">'http:/'</span><span class="sy0">+</span><span class="st0">'/static.flickr.com/'</span> <span class="sy0">+</span> v.<span class="me1">server</span> <span class="sy0">+</span> <span class="st0">'/'</span> <span class="sy0">+</span> v.<span class="me1">id</span> <span class="sy0">+</span> <span class="st0">'_'</span> <span class="sy0">+</span> v.<span class="me1">secret</span> <span class="sy0">+</span> <span class="st0">'_m.jpg'</span><span class="sy0">,</span>
                    <span class="co1">//Create the image and the LI</span>
                    li <span class="sy0">=</span> Y.<span class="me1">Node</span>.<span class="me1">create</span><span class="br0">&#40;</span><span class="st0">'&lt;li class=&quot;loading&quot;&gt;&lt;img src=&quot;'</span> <span class="sy0">+</span> url <span class="sy0">+</span> <span class="st0">'&quot; title=&quot;'</span> <span class="sy0">+</span> v.<span class="me1">title</span> <span class="sy0">+</span> <span class="st0">'&quot;&gt;&lt;/li&gt;'</span><span class="br0">&#41;</span><span class="sy0">,</span>
                    <span class="co1">//Get the image from the LI</span>
                    img <span class="sy0">=</span> li.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'firstChild'</span><span class="br0">&#41;</span><span class="sy0">;</span>
                <span class="co1">//Append the li to the wrapper</span>
                wrapper.<span class="me1">appendChild</span><span class="br0">&#40;</span>li<span class="br0">&#41;</span><span class="sy0">;</span>
                <span class="co1">//This little hack moves the tall images to the bottom of the list</span>
                <span class="co1">//So they float better ;)</span>
                img.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'load'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                    <span class="co1">//Is the height longer than the width?</span>
                    <span class="kw2">var</span> c <span class="sy0">=</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'height'</span><span class="br0">&#41;</span> <span class="sy0">&gt;</span> <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'width'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">?</span> <span class="st0">'tall'</span> <span class="sy0">:</span> <span class="st0">'wide'</span><span class="br0">&#41;</span><span class="sy0">;</span>
                    <span class="kw1">this</span>.<span class="me1">addClass</span><span class="br0">&#40;</span>c<span class="br0">&#41;</span><span class="sy0">;</span>
                    <span class="kw1">if</span> <span class="br0">&#40;</span>c <span class="sy0">===</span> <span class="st0">'tall'</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                        <span class="co1">//Move it to the end of the list.</span>
                        <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode.parentNode'</span><span class="br0">&#41;</span>.<span class="me1">removeChild</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
                        wrapper.<span class="me1">appendChild</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
                    <span class="br0">&#125;</span>
                    <span class="kw1">this</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'loading'</span><span class="br0">&#41;</span><span class="sy0">;</span>
                <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="co1">//Get all the newly added li's</span>
            wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li'</span><span class="br0">&#41;</span>.<span class="me1">each</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>node<span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="co1">//Plugin the Drag plugin</span>
                <span class="kw1">this</span>.<span class="me1">plug</span><span class="br0">&#40;</span>Y.<span class="me1">Plugin</span>.<span class="me1">Drag</span><span class="sy0">,</span> <span class="br0">&#123;</span>
                    offsetNode<span class="sy0">:</span> <span class="kw2">false</span>
                <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
                <span class="co1">//Plug the Proxy into the DD object</span>
                <span class="kw1">this</span>.<span class="me1">dd</span>.<span class="me1">plug</span><span class="br0">&#40;</span>Y.<span class="me1">Plugin</span>.<span class="me1">DDProxy</span><span class="sy0">,</span> <span class="br0">&#123;</span>
                    resizeFrame<span class="sy0">:</span> <span class="kw2">false</span><span class="sy0">,</span>
                    moveOnEnd<span class="sy0">:</span> <span class="kw2">false</span><span class="sy0">,</span>
                    borderStyle<span class="sy0">:</span> <span class="st0">'none'</span>
                <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="co1">//Create and render the slider</span>
            <span class="kw2">var</span> sl <span class="sy0">=</span> <span class="kw2">new</span> Y.<span class="me1">Slider</span><span class="br0">&#40;</span><span class="br0">&#123;</span>
                length<span class="sy0">:</span> <span class="st0">'200px'</span><span class="sy0">,</span> value<span class="sy0">:</span> <span class="nu0">40</span><span class="sy0">,</span> max<span class="sy0">:</span> <span class="nu0">70</span><span class="sy0">,</span> min<span class="sy0">:</span> <span class="nu0">5</span>
            <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">render</span><span class="br0">&#40;</span><span class="st0">'.horiz_slider'</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="co1">//Listen for the change</span>
            sl.<span class="me1">after</span><span class="br0">&#40;</span><span class="st0">'valueChange'</span><span class="sy0">,</span><span class="kw2">function</span> <span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="co1">//Insert a dynamic stylesheet rule</span>
                <span class="kw2">var</span> sheet <span class="sy0">=</span> <span class="kw2">new</span> Y.<span class="me1">StyleSheet</span><span class="br0">&#40;</span><span class="st0">'image_slider'</span><span class="br0">&#41;</span><span class="sy0">;</span>
                sheet.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'#yui-main .yui-g ul li'</span><span class="sy0">,</span> <span class="br0">&#123;</span>
                    width<span class="sy0">:</span> <span class="br0">&#40;</span>e.<span class="me1">newVal</span> <span class="sy0">/</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">'%'</span>
                <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="co1">//Remove the DDM as a bubble target..</span>
            sl._dd.<span class="me1">removeTarget</span><span class="br0">&#40;</span>Y.<span class="me1">DD</span>.<span class="me1">DDM</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="co1">//Remove the wrappers loading class</span>
            wrapper.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'loading'</span><span class="br0">&#41;</span><span class="sy0">;</span>
            Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#ft'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'loading'</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co1">//Listen for all mouseups on the document (selecting/deselecting images)</span>
    Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'delegate'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>e.<span class="me1">shiftKey</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="co1">//No shift key - remove all selected images</span>
            wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'img.selected'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
        <span class="co1">//Check if the target is an image and select it.</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span>e.<span class="me1">target</span>.<span class="me1">test</span><span class="br0">&#40;</span><span class="st0">'#yui-main .yui-g ul li img'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            e.<span class="me1">target</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span><span class="sy0">,</span> document<span class="sy0">,</span> <span class="st0">'mouseup'</span><span class="sy0">,</span> <span class="st0">'*'</span><span class="br0">&#41;</span><span class="sy0">;</span>    
    <span class="co1">//Listen for all clicks on the '#photoList li' selector</span>
    Y.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'delegate'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="co1">//Prevent the click</span>
        e.<span class="me1">halt</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="co1">//Remove all the selected items</span>
        e.<span class="me1">currentTarget</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode'</span><span class="br0">&#41;</span>.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li.selected'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="co1">//Add the selected class to the one that one clicked</span>
        e.<span class="me1">currentTarget</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="co1">//The &quot;All Photos&quot; link was clicked</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span>e.<span class="me1">currentTarget</span>.<span class="me1">hasClass</span><span class="br0">&#40;</span><span class="st0">'all'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="co1">//Remove all the hidden classes</span>
            wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li'</span><span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'hidden'</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
            <span class="co1">//Another &quot;album&quot; was clicked, get its id</span>
            <span class="kw2">var</span> c <span class="sy0">=</span> e.<span class="me1">currentTarget</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'id'</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="co1">//Hide all items by adding the hidden class</span>
            wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li'</span><span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'hidden'</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="co1">//Now, find all the items with the class name the same as the album id</span>
            <span class="co1">//and remove the hidden class</span>
            wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li.'</span> <span class="sy0">+</span> c<span class="br0">&#41;</span>.<span class="me1">removeClass</span><span class="br0">&#40;</span><span class="st0">'hidden'</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span><span class="sy0">,</span> document<span class="sy0">,</span> <span class="st0">'click'</span><span class="sy0">,</span> <span class="st0">'#photoList li'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co1">//Stop the drag with the escape key</span>
    Y.<span class="me1">one</span><span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'keypress'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="co1">//The escape key was pressed</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>e.<span class="me1">keyCode</span> <span class="sy0">===</span> <span class="nu0">27</span><span class="br0">&#41;</span> <span class="sy0">||</span> <span class="br0">&#40;</span>e.<span class="me1">charCode</span> <span class="sy0">===</span> <span class="nu0">27</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="co1">//We have an active Drag</span>
            <span class="kw1">if</span> <span class="br0">&#40;</span>Y.<span class="me1">DD</span>.<span class="me1">DDM</span>.<span class="me1">activeDrag</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="co1">//Stop the drag</span>
                Y.<span class="me1">DD</span>.<span class="me1">DDM</span>.<span class="me1">activeDrag</span>.<span class="me1">stopDrag</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="br0">&#125;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co1">//On the drag:mouseDown add the selected class</span>
    Y.<span class="me1">DD</span>.<span class="me1">DDM</span>.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'drag:mouseDown'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        e.<span class="me1">target</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'node'</span><span class="br0">&#41;</span>.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'img'</span><span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span><span class="st0">'selected'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co1">//On drag start, get all the selected elements</span>
    <span class="co1">//Add the count to the proxy element and offset it to the cursor.</span>
    Y.<span class="me1">DD</span>.<span class="me1">DDM</span>.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'drag:start'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="co1">//How many items are selected</span>
        <span class="kw2">var</span> count <span class="sy0">=</span> wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'img.selected'</span><span class="br0">&#41;</span>.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="co1">//Set the style on the proxy node</span>
        e.<span class="me1">target</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'dragNode'</span><span class="br0">&#41;</span>.<span class="me1">setStyles</span><span class="br0">&#40;</span><span class="br0">&#123;</span>
            height<span class="sy0">:</span> <span class="st0">'25px'</span><span class="sy0">,</span> width<span class="sy0">:</span> <span class="st0">'25px'</span>
        <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'innerHTML'</span><span class="sy0">,</span> <span class="st0">'&lt;span&gt;'</span> <span class="sy0">+</span> count <span class="sy0">+</span> <span class="st0">'&lt;/span&gt;'</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="co1">//Offset the dragNode</span>
        e.<span class="me1">target</span>.<span class="me1">deltaXY</span> <span class="sy0">=</span> <span class="br0">&#91;</span><span class="nu0">25</span><span class="sy0">,</span> <span class="nu0">5</span><span class="br0">&#93;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co1">//We dropped on a drop target</span>
    Y.<span class="me1">DD</span>.<span class="me1">DDM</span>.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'drag:drophit'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="co1">//get the images that are selected.</span>
        <span class="kw2">var</span> imgs <span class="sy0">=</span> wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'img.selected'</span><span class="br0">&#41;</span><span class="sy0">,</span>
            <span class="co1">//The xy position of the item we dropped on</span>
            toXY <span class="sy0">=</span> e.<span class="me1">drop</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'node'</span><span class="br0">&#41;</span>.<span class="me1">getXY</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
        imgs.<span class="me1">each</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>node<span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="co1">//Clone the image, position it on top of the original and animate it to the drop target</span>
            node.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'parentNode'</span><span class="br0">&#41;</span>.<span class="me1">addClass</span><span class="br0">&#40;</span>e.<span class="me1">drop</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'node'</span><span class="br0">&#41;</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'id'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="kw2">var</span> n <span class="sy0">=</span> node.<span class="me1">cloneNode</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'id'</span><span class="sy0">,</span> <span class="st0">''</span><span class="br0">&#41;</span>.<span class="me1">setStyle</span><span class="br0">&#40;</span><span class="st0">'position'</span><span class="sy0">,</span> <span class="st0">'absolute'</span><span class="br0">&#41;</span><span class="sy0">;</span>
            Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'body'</span><span class="br0">&#41;</span>.<span class="me1">appendChild</span><span class="br0">&#40;</span>n<span class="br0">&#41;</span><span class="sy0">;</span>
            n.<span class="me1">setXY</span><span class="br0">&#40;</span>node.<span class="me1">getXY</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="kw2">new</span> Y.<span class="me1">Anim</span><span class="br0">&#40;</span><span class="br0">&#123;</span>
                node<span class="sy0">:</span> n<span class="sy0">,</span>
                to<span class="sy0">:</span> <span class="br0">&#123;</span>
                    height<span class="sy0">:</span> <span class="nu0">20</span><span class="sy0">,</span> width<span class="sy0">:</span> <span class="nu0">20</span><span class="sy0">,</span> opacity<span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">,</span>
                    top<span class="sy0">:</span> toXY<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="sy0">,</span> left<span class="sy0">:</span> toXY<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>
                <span class="br0">&#125;</span><span class="sy0">,</span>
                from<span class="sy0">:</span> <span class="br0">&#123;</span>
                    width<span class="sy0">:</span> node.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'offsetWidth'</span><span class="br0">&#41;</span><span class="sy0">,</span>
                    height<span class="sy0">:</span> node.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'offsetHeight'</span><span class="br0">&#41;</span>
                <span class="br0">&#125;</span><span class="sy0">,</span>
                duration<span class="sy0">:</span> .5
            <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">run</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="co1">//Update the count</span>
        <span class="kw2">var</span> count <span class="sy0">=</span> wrapper.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'li.'</span> <span class="sy0">+</span> e.<span class="me1">drop</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'node'</span><span class="br0">&#41;</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'id'</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        e.<span class="me1">drop</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">'node'</span><span class="br0">&#41;</span>.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'span'</span><span class="br0">&#41;</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'innerHTML'</span><span class="sy0">,</span> <span class="st0">'('</span> <span class="sy0">+</span> count <span class="sy0">+</span> <span class="st0">')'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="co1">//Add drop support to the albums</span>
    Y.<span class="me1">all</span><span class="br0">&#40;</span><span class="st0">'#photoList li'</span><span class="br0">&#41;</span>.<span class="me1">each</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>node<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>node.<span class="me1">hasClass</span><span class="br0">&#40;</span><span class="st0">'all'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="co1">//make all albums Drop Targets except the all photos.</span>
            node.<span class="me1">plug</span><span class="br0">&#40;</span>Y.<span class="me1">Plugin</span>.<span class="me1">Drop</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div><textarea id="syntax-1c523152372eedf102f48b5660168c42-plain">YUI().use('gallery-yql', 'node', 'anim', 'dd', 'slider', 'stylesheet', 'event-delegate', function(Y) {
    //Get a reference to the wrapper to use later and add a loading class to it.
    var wrapper = Y.one('#yui-main .yui-g ul').addClass('loading');
    //Set its height to the height of the viewport so we can scroll it.
    wrapper.setStyle('height', (wrapper.get('winHeight') - 50 )+ 'px');
    Y.on('windowresize', function() { wrapper.setStyle('height', (wrapper.get('winHeight') - 50 )+ 'px'); });
    //Make the YQL query.
    new Y.yql('select * from flickr.photos.search(100) where text="openhacklondon" and safe_search = 1 and media = "photos" and extras = "o_dims" and ((o_width = "1600" and o_height = "1200") or (o_width = "1200" and o_height = "1600") or (o_width = "800" and o_height = "600") or (o_width = "600" and o_height = "800"))', function(e) {
        if (e.query) {
            var photos = e.query.results.photo;
            //Walk the returned photos array
            Y.each(photos, function(v, k) {
                //Create our URL
                var url = 'http:/'+'/static.flickr.com/' + v.server + '/' + v.id + '_' + v.secret + '_m.jpg',
                    //Create the image and the LI
                    li = Y.Node.create('<li class="loading"><img src="' + url + '" title="' + v.title + '"></li>'),
                    //Get the image from the LI
                    img = li.get('firstChild');
                //Append the li to the wrapper
                wrapper.appendChild(li);
                //This little hack moves the tall images to the bottom of the list
                //So they float better ;)
                img.on('load', function() {
                    //Is the height longer than the width?
                    var c = ((this.get('height') > this.get('width')) ? 'tall' : 'wide');
                    this.addClass(c);
                    if (c === 'tall') {
                        //Move it to the end of the list.
                        this.get('parentNode.parentNode').removeChild(this.get('parentNode'));
                        wrapper.appendChild(this.get('parentNode'));
                    }
                    this.get('parentNode').removeClass('loading');
                });
            });
            //Get all the newly added li's
            wrapper.all('li').each(function(node) {
                //Plugin the Drag plugin
                this.plug(Y.Plugin.Drag, {
                    offsetNode: false
                });
                //Plug the Proxy into the DD object
                this.dd.plug(Y.Plugin.DDProxy, {
                    resizeFrame: false,
                    moveOnEnd: false,
                    borderStyle: 'none'
                });
            });
            //Create and render the slider
            var sl = new Y.Slider({
                length: '200px', value: 40, max: 70, min: 5
            }).render('.horiz_slider');
            //Listen for the change
            sl.after('valueChange',function (e) {
                //Insert a dynamic stylesheet rule
                var sheet = new Y.StyleSheet('image_slider');
                sheet.set('#yui-main .yui-g ul li', {
                    width: (e.newVal / 2) + '%'
                });
            });
            //Remove the DDM as a bubble target..
            sl._dd.removeTarget(Y.DD.DDM);
            //Remove the wrappers loading class
            wrapper.removeClass('loading');
            Y.one('#ft').removeClass('loading');
        }
    });
    //Listen for all mouseups on the document (selecting/deselecting images)
    Y.on('delegate', function(e) {
        if (!e.shiftKey) {
            //No shift key - remove all selected images
            wrapper.all('img.selected').removeClass('selected');
        }
        //Check if the target is an image and select it.
        if (e.target.test('#yui-main .yui-g ul li img')) {
            e.target.addClass('selected');
        }
    }, document, 'mouseup', '*');    
    //Listen for all clicks on the '#photoList li' selector
    Y.on('delegate', function(e) {
        //Prevent the click
        e.halt();
        //Remove all the selected items
        e.currentTarget.get('parentNode').all('li.selected').removeClass('selected');
        //Add the selected class to the one that one clicked
        e.currentTarget.addClass('selected');
        //The "All Photos" link was clicked
        if (e.currentTarget.hasClass('all')) {
            //Remove all the hidden classes
            wrapper.all('li').removeClass('hidden');
        } else {
            //Another "album" was clicked, get its id
            var c = e.currentTarget.get('id');
            //Hide all items by adding the hidden class
            wrapper.all('li').addClass('hidden');
            //Now, find all the items with the class name the same as the album id
            //and remove the hidden class
            wrapper.all('li.' + c).removeClass('hidden');
        }
    }, document, 'click', '#photoList li');
    //Stop the drag with the escape key
    Y.one(document).on('keypress', function(e) {
        //The escape key was pressed
        if ((e.keyCode === 27) || (e.charCode === 27)) {
            //We have an active Drag
            if (Y.DD.DDM.activeDrag) {
                //Stop the drag
                Y.DD.DDM.activeDrag.stopDrag();
            }
        }
    });
    //On the drag:mouseDown add the selected class
    Y.DD.DDM.on('drag:mouseDown', function(e) {
        e.target.get('node').all('img').addClass('selected');
    });
    //On drag start, get all the selected elements
    //Add the count to the proxy element and offset it to the cursor.
    Y.DD.DDM.on('drag:start', function(e) {
        //How many items are selected
        var count = wrapper.all('img.selected').size();
        //Set the style on the proxy node
        e.target.get('dragNode').setStyles({
            height: '25px', width: '25px'
        }).set('innerHTML', '<span>' + count + '</span>');
        //Offset the dragNode
        e.target.deltaXY = [25, 5];
    });
    //We dropped on a drop target
    Y.DD.DDM.on('drag:drophit', function(e) {
        //get the images that are selected.
        var imgs = wrapper.all('img.selected'),
            //The xy position of the item we dropped on
            toXY = e.drop.get('node').getXY();
        
        imgs.each(function(node) {
            //Clone the image, position it on top of the original and animate it to the drop target
            node.get('parentNode').addClass(e.drop.get('node').get('id'));
            var n = node.cloneNode().set('id', '').setStyle('position', 'absolute');
            Y.one('body').appendChild(n);
            n.setXY(node.getXY());
            new Y.Anim({
                node: n,
                to: {
                    height: 20, width: 20, opacity: 0,
                    top: toXY[1], left: toXY[0]
                },
                from: {
                    width: node.get('offsetWidth'),
                    height: node.get('offsetHeight')
                },
                duration: .5
            }).run();
        });
        //Update the count
        var count = wrapper.all('li.' + e.drop.get('node').get('id')).size();
        e.drop.get('node').one('span').set('innerHTML', '(' + count + ')');
    });
    //Add drop support to the albums
    Y.all('#photoList li').each(function(node) {
        if (!node.hasClass('all')) {
            //make all albums Drop Targets except the all photos.
            node.plug(Y.Plugin.Drop);
        }
    });
});</textarea></div>
				</div>
				<div class="yui-u sidebar">
					
				
					<div id="examples" class="mod box4">
                        <div class="hd">
						<h4>
    Drag &amp; Drop Examples:</h4>
                        </div>
						<div class="bd">
							<ul>
								<li><a href='../dd/simple-drag.html'>Simple Drag</a></li><li><a href='../dd/drag-plugin.html'>Drag Node Plugin</a></li><li><a href='../dd/proxy-drag.html'>Proxy Drag</a></li><li><a href='../dd/constrained-drag.html'>Drag Constrained to a Region</a></li><li><a href='../dd/groups-drag.html'>Interaction Groups</a></li><li><a href='../dd/shim-drag.html'>Using the Drag Shim</a></li><li><a href='../dd/anim-drop.html'>Animated Drop Targets</a></li><li><a href='../dd/drop-code.html'>Drop Based Coding</a></li><li><a href='../dd/winscroll.html'>Window Scrolling</a></li><li><a href='../dd/delegate.html'>Drag Delegation</a></li><li><a href='../dd/delegate-drop.html'>Drag Delegation with a Drop Target</a></li><li><a href='../dd/delegate-plugins.html'>Using Drag plugins with Delegate</a></li><li><a href='../dd/list-drag.html'>List reorder w/Bubbling</a></li><li><a href='../dd/scroll-list.html'>List reorder w/Scrolling</a></li><li><a href='../dd/portal-drag.html'>Portal Style Example</a></li><li class='selected'><a href='../dd/photo-browser.html'>Photo Browser</a></li><li><a href='../stylesheet/stylesheet_theme.html'>Adjusting a page theme on the fly (included with examples for StyleSheet)</a></li>							</ul>
						</div>
					</div>
					
					<div class="mod box4">
                        <div class="hd">
						<h4>More Drag &amp; Drop Resources:</h4>
                        </div>
                        <div class="bd">
						<ul>
							<!-- <li><a href="http://developer.yahoo.com/yui/dd/">User's Guide</a> (external)</li> -->
<li><a href="../../api/module_dd.html">API Documentation</a></li></ul>
                        </div>
					</div>
			  </div>
		</div>
		
		</div>
	</div>


<div class="yui-b toc3" id="tocWrapper">
<!-- TABLE OF CONTENTS -->
<div id="toc">
	
<ul>
<li class="sect first">YUI 3 Resources</li><li class="item"><a title="YUI 3 -- Yahoo! User Interface (YUI) Library" href="http://developer.yahoo.com/yui/3/">YUI 3 Web Site</a></li><li class="item"><a title="Examples of every YUI utility and control in action" href="../../examples/">YUI 3 Examples</a></li><li class="item"><a title="Instantly searchable API documentation for the entire YUI library." href="../../api/">YUI 3 API Docs</a></li><li class="item"><a title="YUI 3 Dependency Configurator -- configure your custom YUI implementation" href="http://developer.yahoo.com/yui/3/configurator/index.html">YUI 3 Dependency Configurator</a></li><li class="item"><a title="The YUI 3 Forum on YUILibrary.com" href="http://yuilibrary.com/forum/viewforum.php?f=15">YUI 3 Forums (external)</a></li><li class="item"><a title="Found a bug or a missing feature? Let us know on YUILibrary.com." href="http://developer.yahoo.com/yui/articles/reportingbugs/">Bug Reports/Feature Requests</a></li><li class="item"><a title="YUI is free and open, offered under a BSD license." href="http://developer.yahoo.com/yui/license.html">YUI License</a></li><li class="item"><a title="Download and fork the YUI project on GitHub" href="http://github.com/yui">YUI on Github</a></li><li class="item"><a title="The Yahoo! User Interface Blog" href="http://yuiblog.com">YUI Blog (external)</a></li><li class="sect">YUI 3 Core - Examples</li><li class="item"><a title="YUI Global Object - Functional Examples" href="../../examples/yui/index.html">YUI Global Object</a></li><li class="item"><a title="Event - Functional Examples" href="../../examples/event/index.html">Event</a></li><li class="item"><a title="Node - Functional Examples" href="../../examples/node/index.html">Node</a></li><li class="sect">YUI 3 Component Infrastructure - Examples</li><li class="item"><a title="Attribute - Functional Examples" href="../../examples/attribute/index.html">Attribute</a></li><li class="item"><a title="Plugin - Functional Examples" href="../../examples/plugin/index.html">Plugin</a></li><li class="item"><a title="Widget - Functional Examples" href="../../examples/widget/index.html">Widget</a></li><li class="sect">YUI 3 Utilities - Examples</li><li class="item"><a title="Animation - Functional Examples" href="../../examples/anim/index.html">Animation</a></li><li class="item"><a title="AsyncQueue - Functional Examples" href="../../examples/async-queue/index.html">AsyncQueue</a></li><li class="item"><a title="Browser History - Functional Examples" href="../../examples/history/index.html">Browser History</a></li><li class="item"><a title="Cache - Functional Examples" href="../../examples/cache/index.html">Cache</a></li><li class="item"><a title="Cookie - Functional Examples" href="../../examples/cookie/index.html">Cookie</a></li><li class="item"><a title="DataSchema - Functional Examples" href="../../examples/dataschema/index.html">DataSchema <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="DataSource - Functional Examples" href="../../examples/datasource/index.html">DataSource <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="DataType - Functional Examples" href="../../examples/datatype/index.html">DataType <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="selected "><a title="Drag &amp; Drop - Functional Examples" href="../../examples/dd/index.html">Drag &amp; Drop</a></li><li class="item"><a title="Get - Functional Examples" href="../../examples/get/index.html">Get</a></li><li class="item"><a title="ImageLoader - Functional Examples" href="../../examples/imageloader/index.html">ImageLoader</a></li><li class="item"><a title="Internationalization - Functional Examples" href="../../examples/intl/index.html">Internationalization <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="IO - Functional Examples" href="../../examples/io/index.html">IO</a></li><li class="item"><a title="JSON (JavaScript Object Notation) - Functional Examples" href="../../examples/json/index.html">JSON</a></li><li class="item"><a title="Stylesheet - Functional Examples" href="../../examples/stylesheet/index.html">Stylesheet</a></li><li class="sect">YUI 3 Widgets - Examples</li><li class="item"><a title="Overlay - Functional Examples" href="../../examples/overlay/index.html">Overlay <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Slider - Functional Examples" href="../../examples/slider/index.html">Slider <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Tabview - Functional Examples" href="../../examples/tabview/index.html">Tabview <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 Node Plugins - Examples</li><li class="item"><a title="FocusManager Node Plugin - Functional Examples" href="../../examples/node-focusmanager/index.html">FocusManager Node Plugin <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="MenuNav Node Plugin - Functional Examples" href="../../examples/node-menunav/index.html">MenuNav Node Plugin <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 CSS - Examples</li><li class="item"><a title="YUI CSS Reset - Functional Examples" href="../../examples/cssreset/index.html">CSS Reset</a></li><li class="item"><a title="YUI Fonts - Functional Examples" href="../../examples/cssfonts/index.html">CSS Fonts</a></li><li class="item"><a title="YUI Base - Functional Examples" href="../../examples/cssbase/index.html">CSS Base</a></li><li class="sect">YUI 3 Developer Tools - Examples</li><li class="item"><a title="Console - Functional Examples" href="../../examples/console/index.html">Console <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Console Filters Plugin- Functional Examples" href="../../examples/console-filters/index.html">Plugin.ConsoleFilters <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Profiler - Functional Examples" href="../../examples/profiler/index.html">Profiler</a></li><li class="item"><a title="Test - Functional Examples" href="../../examples/test/index.html">Test</a></li><li class="sect">Other Useful YUI 3 Resources</li><li class="item"><a title="Answers to Frequently Asked Questions about the YUI Library" href="http://developer.yahoo.com/yui/articles/faq/">YUI FAQ (external)</a></li><li class="item"><a title="Yahoo!'s philosophy of Graded Browser Support" href="http://developer.yahoo.com/yui/articles/gbs/">Graded Browser Support (external)</a></li><li class="item"><a title="Videos and podcasts from the YUI Team and from the Yahoo! frontend engineering community." href="http://developer.yahoo.com/yui/theater/">YUI Theater (external)</a></li></ul>
</div>
</div>
	</div><!--closes bd-->

	<div id="ft">
        <p class="first">Copyright &copy; 2010 Yahoo! Inc. All rights reserved.</p>
        <p><a href="http://privacy.yahoo.com/privacy/us/devel/index.html">Privacy Policy</a> - 
            <a href="http://docs.yahoo.com/info/terms/">Terms of Service</a> - 
            <a href="http://docs.yahoo.com/info/copyright/copyright.html">Copyright Policy</a> - 
            <a href="http://careers.yahoo.com/">Job Openings</a></p>
	</div>
</div>
<script language="javascript"> 
var yuiConfig = {};
</script>
<script src="../../assets/syntax.js"></script>
<script src="../../assets/dpSyntaxHighlighter.js"></script>
<script language="javascript"> 
dp.SyntaxHighlighter.HighlightAll('code'); 
</script>
</body>
</html>
